package com.eshop.modules.shop.rest;

import org.springframework.web.bind.annotation.DeleteMapping;
import java.io.Serializable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import com.eshop.modules.aop.ForbidSubmit;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.validation.annotation.Validated;
import com.eshop.modules.shop.domain.MaterialGroup;
import io.swagger.annotations.ApiOperation;
import com.eshop.logging.aop.log.Log;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.shop.service.dto.MaterialGroupQueryCriteria;
import com.eshop.modules.shop.service.MaterialGroupService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;

@Api(tags = { "商城:素材分组管理" })
@RestController
@RequestMapping({ "/api/materialgroup" })
public class MaterialGroupController
{
    private final MaterialGroupService materialGroupService;
    
    public MaterialGroupController(final MaterialGroupService materialGroupService) {
        this.materialGroupService = materialGroupService;
    }
    
    @GetMapping({ "/page" })
    @Log("查询素材分组")
    @ApiOperation("查询素材分组")
    public ResponseEntity<Object> getYxMaterialGroups(final MaterialGroupQueryCriteria criteria, final Pageable pageable) {
        return new ResponseEntity(this.materialGroupService.queryAll(criteria, pageable), HttpStatus.OK);
    }
    
    @GetMapping({ "/list" })
    @Log("查询所有素材分组")
    @ApiOperation("查询所有素材分组")
    public ResponseEntity<Object> getYxMaterialGroupsList(final MaterialGroupQueryCriteria criteria) {
        return new ResponseEntity(this.materialGroupService.queryAll(criteria), HttpStatus.OK);
    }
    
    @PostMapping
    @Log("新增素材分组")
    @ApiOperation("新增素材分组")
    public ResponseEntity<Object> create(@Validated @RequestBody final MaterialGroup resources) {
        return new ResponseEntity(this.materialGroupService.save(resources), HttpStatus.CREATED);
    }
    
    @ForbidSubmit
    @PutMapping
    @Log("修改素材分组")
    @ApiOperation("修改素材分组")
    public ResponseEntity<Object> update(@Validated @RequestBody final MaterialGroup resources) {
        this.materialGroupService.saveOrUpdate(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }
    
    @ForbidSubmit
    @Log("删除素材分组")
    @ApiOperation("删除素材分组")
    @DeleteMapping({ "/{id}" })
    public ResponseEntity<Object> deleteAll(@PathVariable final String id) {
        this.materialGroupService.removeById((Serializable)id);
        return new ResponseEntity(HttpStatus.OK);
    }
}
